<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="学校名称" prop="collegialNanem">
        <el-input
          v-model="queryParams.collegialNanem"
          placeholder="请输入学校名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="办学层次(本科)" prop="collegialGradation">
        <el-input
          v-model="queryParams.collegialGradation"
          placeholder="请输入办学层次(本科)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="学校标注(双一流/985/211等)" prop="collegialLabel">
        <el-input
          v-model="queryParams.collegialLabel"
          placeholder="请输入学校标注(双一流/985/211等)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="办学性质(私立/公立)" prop="collegialNature">
        <el-input
          v-model="queryParams.collegialNature"
          placeholder="请输入办学性质(私立/公立)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="院校类型(理工类/综合类)" prop="collegialType">
        <el-select v-model="queryParams.collegialType" placeholder="请选择院校类型(理工类/综合类)" clearable>
          <el-option
            v-for="dict in dict.type.info_collegial_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="主管单位" prop="competentAuthority">
        <el-input
          v-model="queryParams.competentAuthority"
          placeholder="请输入主管单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['infoCollegial:colletgial:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['infoCollegial:colletgial:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['infoCollegial:colletgial:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['infoCollegial:colletgial:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="colletgialList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="学校名称" align="center" prop="collegialNanem" />
      <el-table-column label="办学层次(本科)" align="center" prop="collegialGradation">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.info_degree" :value="scope.row.collegialGradation"/>
        </template>
      </el-table-column>
      <el-table-column label="办学性质(私立/公立)" align="center" prop="collegialNature">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.info_collegial_nature" :value="scope.row.collegialNature"/>
        </template>
      </el-table-column>
      <el-table-column label="院校类型(理工类/综合类)" align="center" prop="collegialType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.info_collegial_type" :value="scope.row.collegialType"/>
        </template>
      </el-table-column>
      <el-table-column label="主管单位" align="center" prop="competentAuthority" />
      <el-table-column label="创办时间" align="center" prop="collegialCreationTime" />
      <el-table-column label="校徽" align="center" prop="collegialBadge" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['infoCollegial:colletgial:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['infoCollegial:colletgial:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改院校主对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="学校名称" prop="collegialNanem">
          <el-input v-model="form.collegialNanem" placeholder="请输入学校名称" />
        </el-form-item>
        <el-form-item label="办学层次(本科)" prop="collegialGradation">
          <el-input v-model="form.collegialGradation" placeholder="请输入办学层次(本科)" />
        </el-form-item>
        <el-form-item label="学校标注(双一流/985/211等)" prop="collegialLabel">
          <el-input v-model="form.collegialLabel" placeholder="请输入学校标注(双一流/985/211等)" />
        </el-form-item>
        <el-form-item label="办学性质(私立/公立)" prop="collegialNature">
          <el-input v-model="form.collegialNature" placeholder="请输入办学性质(私立/公立)" />
        </el-form-item>
        <el-form-item label="院校类型(理工类/综合类)" prop="collegialType">
          <el-select v-model="form.collegialType" placeholder="请选择院校类型(理工类/综合类)">
            <el-option
              v-for="dict in dict.type.info_collegial_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="主管单位" prop="competentAuthority">
          <el-input v-model="form.competentAuthority" placeholder="请输入主管单位" />
        </el-form-item>
        <el-form-item label="创办时间" prop="collegialCreationTime">
          <el-input v-model="form.collegialCreationTime" placeholder="请输入创办时间" />
        </el-form-item>
        <el-form-item label="校徽" prop="collegialBadge">
          <el-input v-model="form.collegialBadge" placeholder="请输入校徽" />
        </el-form-item>
        <el-form-item label="简介" prop="collegialSynopsis">
          <el-input v-model="form.collegialSynopsis" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="招生官网" prop="admissionsWebsite">
          <el-input v-model="form.admissionsWebsite" placeholder="请输入招生官网" />
        </el-form-item>
        <el-form-item label="学校官网" prop="collegialWebsite">
          <el-input v-model="form.collegialWebsite" placeholder="请输入学校官网" />
        </el-form-item>
        <el-form-item label="学校所在地" prop="collegialAddress">
          <el-input v-model="form.collegialAddress" placeholder="请输入学校所在地" />
        </el-form-item>
        <el-form-item label="联系电话" prop="collegialPhone">
          <el-input v-model="form.collegialPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="博士点" prop="doctorDot">
          <el-input v-model="form.doctorDot" placeholder="请输入博士点" />
        </el-form-item>
        <el-form-item label="硕士点(数量)" prop="masterDot">
          <el-input v-model="form.masterDot" placeholder="请输入硕士点(数量)" />
        </el-form-item>
        <el-form-item label="重点学科(数量)" prop="keySubject">
          <el-input v-model="form.keySubject" placeholder="请输入重点学科(数量)" />
        </el-form-item>
        <el-form-item label="院士人数" prop="subjectDot">
          <el-input v-model="form.subjectDot" placeholder="请输入院士人数" />
        </el-form-item>
        <el-form-item label="学生人数(区间)" prop="studentRegion">
          <el-input v-model="form.studentRegion" placeholder="请输入学生人数(区间)" />
        </el-form-item>
        <el-form-item label="排序" prop="orderSort">
          <el-input v-model="form.orderSort" placeholder="请输入排序" />
        </el-form-item>
        <el-form-item label="外链" prop="backlinks">
          <el-input v-model="form.backlinks" placeholder="请输入外链" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listColletgial, getColletgial, delColletgial, addColletgial, updateColletgial } from "@/api/infoCollegial/colletgial";

export default {
  name: "Colletgial",
  dicts: ['info_collegial_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 院校主表格数据
      colletgialList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        collegialNanem: null,
        collegialGradation: null,
        collegialLabel: null,
        collegialNature: null,
        collegialType: null,
        competentAuthority: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询院校主列表 */
    getList() {
      this.loading = true;
      listColletgial(this.queryParams).then(response => {
        this.colletgialList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        collegialNanem: null,
        collegialGradation: null,
        collegialLabel: null,
        collegialNature: null,
        collegialType: null,
        competentAuthority: null,
        collegialCreationTime: null,
        collegialBadge: null,
        collegialSynopsis: null,
        admissionsWebsite: null,
        collegialWebsite: null,
        collegialAddress: null,
        collegialPhone: null,
        doctorDot: null,
        masterDot: null,
        keySubject: null,
        subjectDot: null,
        studentRegion: null,
        orderSort: null,
        backlinks: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加院校主";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getColletgial(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改院校主";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateColletgial(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addColletgial(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除院校主编号为"' + ids + '"的数据项？').then(function() {
        return delColletgial(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('infoCollegial/colletgial/export', {
        ...this.queryParams
      }, `colletgial_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
